import { useThrottle } from 'ahooks';
import { useState } from 'react';

const useLoadingState = () => {
  const [_loading, setLoading] = useState<boolean>(false);

  const loading = useThrottle(_loading, { wait: 200 });

  const beginLoading = () => {
    setLoading(true);
  };

  const endLoading = () => {
    setLoading(false);
  };

  return {
    value: loading,
    begin: beginLoading,
    end: endLoading,
  };
};

export default useLoadingState;
